package com.tolerate.managespringboot.common;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class Result<T> {

    private Integer code;//编码：200成功，500和其它数字为失败

    private String msg;//错误信息

    private T data;//数据


    public static <T> Result<T> success(T object) {
        Result<T> result = new Result<T>();
        result.data = object;
        result.code = Constants.SUCCESS_200.getCode();
        return result;
    }

    public static <T> Result<T> success() {
        Result<T> result = new Result<T>();
        result.code = Constants.SUCCESS_200.getCode();
        return result;
    }

    public static <T> Result<T> error(String msg) {
        Result result = new Result();
        result.msg = msg;
        result.code = Constants.FAIL_500.getCode();
        return result;
    }

    public static <T> Result<T> error(Integer code, String msg) {
        Result result = new Result();
        result.msg = msg;
        result.code = code;
        return result;
    }


    public static <T> Result<T> error() {
        Result result = new Result();
        result.code = Constants.FAIL_500.getCode();
        return result;
    }
}
